package file;

import java.io.File;
import java.io.FilenameFilter;

/*
A:文件名称过滤器的概述
public String[] list(FilenameFilter filter)
public File[] listFiles(FileFilter filter)
B:文件名称过滤器的使用
需求：判断E盘目录下是否有后缀名为.jpg的文件，如果有，就输出该文件名称
C:源码分析
带文件名称过滤器的list()方法的源码
 */
public class Demo07_Test_FilenameFilter {
    public static void main(String[] args) {
        File file = new File("E:\\");

        String[] arr = file.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                //System.out.println(dir);
                //dir是盘符名,就是File构造方法中传入的名字
                //System.out.println(name);
                //name是该盘符下的文件的名字
                File file1 = new File(dir,name);
                return file1.isFile() && file1.getName().endsWith(".exe");

            }
        });

        //用Lambda表达式写
//        String[] arr = file.list(((dir, name) -> new File(dir,name).isFile() &&
//                new File(dir,name).getName().endsWith(".exe")));

        for (String s :arr){
            System.out.println(s);
        }
        /*
        DispcapHelper.exe
        Error.exe
        GATESRV.exe
        install.exe
        InstHelpApp.exe
        InstHelpApp64.exe
        MasterHelper.exe
        ProcHelper64.exe
        Shutdown.exe
        SpecialSet.exe
        StudentMain.exe
        TDChalk.exe
        TDOvrSet.exe
        unins000.exe
        VRCwPlayer.exe
         */

    }
}
